package ch5;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLDecoder;

@WebServlet(name = "CookiesServlet1",value = "/showCookie")
public class CookiesServlet1 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
                this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        Cookie[] cookies=request.getCookies();
        for (Cookie tmp :cookies){
            System.out.println("Cookie的名字是"+tmp.getName());
            System.out.println("Cookie的值是"+tmp.getValue());
            if (tmp.getName().equals("time")){
                String de_value= URLDecoder.decode(tmp.getValue(),"utf-8");
                System.out.println("time的解码是"+de_value);
            }
        }
    }
}
